package com.bw.wxy.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class CircleView extends View {
    private int num=15;

    public CircleView(Context context) {
        super(context);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
    public CircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(100,100);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setStrokeWidth(20);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        int scx=getMeasuredWidth()/2;
        int scy=getMeasuredHeight()/2;
        int radius=getMeasuredHeight()/2>getMeasuredWidth()/2?getMeasuredWidth()/2-num:getMeasuredHeight()/2-num;

        canvas.drawCircle(scx,scy,radius,paint);
        paint.setColor(Color.WHITE);
        paint.setTextSize(40);
        paint.setStrokeWidth(2);
        Rect rect = new Rect();
        String s = 3+"";
        paint.getTextBounds(s,0,s.length(),rect);
        canvas.drawText(s,getMeasuredWidth()/2-rect.width()/2,getMeasuredHeight()/2+rect.height()/2,paint);

    }
}

